package cn.sc.summer.summerboot.config;

import cn.sc.summer.protocol.properties.MinioProperties;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * 类名：minio配置信息
 *
 * @author a-xin
 * @date 2023/8/29 14:17
 */
@Slf4j
@Data
@Configuration
public class MinioConfig {

    @Resource
    private MinioProperties minioProperties;

    @Bean
    public MinioClient getMinioClient() throws InvalidPortException, InvalidEndpointException {
        log.info("==> Start connecting to the minio distributed storage service：{}:{}", minioProperties.getUrl(), minioProperties.getPort());
        MinioClient minioClient = new MinioClient(minioProperties.getUrl(), minioProperties.getPort(), minioProperties.getAccessKey(), minioProperties.getSecretKey(), false);
        log.info("==> Minio distributed storage service connection successful！");
        return minioClient;
    }

}
